//index.js  
//获取应用实例  
var app = getApp(), t = app.requirejs("core"), a = app.requirejs("wxParse/wxParse"), i = app.requirejs("biz/diypage");
Page({
  data: {
    /** 
        * 页面配置 
        */
    winWidth: 0,
    winHeight: 0,
    // tab切换  
    currentTab: 0,

    // 产品假数据
    listshop: [
      { 'time': '05/19/2018', 'type': '一级', 'img': 'http://img0.imgtn.bdimg.com/it/u=389466677,1201766833&fm=27&gp=0.jpg', 'name': 'Margin_Wang', 'num': '1', 'money': '598', 'bind1': '######', 'bind2': '######', 'bind3': '######' },
      { 'time': '05/19/2018', 'type': '二级', 'img': 'http://img0.imgtn.bdimg.com/it/u=389466677,1201766833&fm=27&gp=0.jpg', 'name': 'Margin_Wang', 'num': '5', 'money': '98', 'bind1': '######', 'bind2': '######', 'bind3': '######' },
      { 'time': '05/19/2018', 'type': '三级', 'img': 'http://img0.imgtn.bdimg.com/it/u=389466677,1201766833&fm=27&gp=0.jpg', 'name': 'Margin_Wang', 'num': '9', 'money': '199', 'bind1': '######', 'bind2': '######', 'bind3': '######' },
      { 'time': '05/19/2018', 'type': '二级', 'img': 'http://img0.imgtn.bdimg.com/it/u=389466677,1201766833&fm=27&gp=0.jpg', 'name': 'Margin_Wang', 'num': '3', 'money': '199', 'bind1': '######', 'bind2': '######', 'bind3': '######' },
      { 'time': '05/19/2018', 'type': '三级', 'img': 'http://img0.imgtn.bdimg.com/it/u=389466677,1201766833&fm=27&gp=0.jpg', 'name': 'Margin_Wang', 'num': '5', 'money': '199', 'bind1': '######', 'bind2': '######', 'bind3': '######' },
      { 'time': '05/19/2018', 'type': '三级', 'img': 'http://img0.imgtn.bdimg.com/it/u=389466677,1201766833&fm=27&gp=0.jpg', 'name': 'Margin_Wang', 'num': '2', 'money': '199', 'bind1': '######', 'bind2': '######', 'bind3': '######' },
      { 'time': '05/19/2018', 'type': '一级', 'img': 'http://www.xinmoo.cn/uploadfile/graphy/large/20150306100857m821gawc.jpg?location=Lcenter', 'name': 'skincare护肤品', 'num': '1', 'money': '998', 'bind1': '######', 'bind2': '######', 'bind3': '######' },

    ],


  },
  onLoad: function () {
    var that = this;

    /** 
     * 获取系统信息 
     */
    wx.getSystemInfo({

      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }

    });
    t.get("member/index/getMyTeam", {}, function (e) {
      var provinceAgent = [],cityAgent = [],areaAgent = [];
      e.forEach(function(val,key){
        if (val.aagenttype == 1) provinceAgent.push(val);
        if (val.aagenttype == 2) cityAgent.push(val);
        if (val.aagenttype == 3) areaAgent.push(val);
      })
      that.setData({
        showItem: provinceAgent,
        provinceAgent: provinceAgent,
        cityAgent: cityAgent,
        areaAgent: areaAgent
      })
    });
  },
  /** 
     * 滑动切换tab 
     */
  // bindChange: function (e) {
  //   console.loh(bindChange)
  //   var that = this;
  //   that.setData({ currentTab: e.detail.current });

  // },
  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {

    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      var showItem = [];
      switch (Number(e.target.dataset.current)){
        case 0:
          showItem = this.data.provinceAgent;
          console.log("省级代理")
          break;
        case 1:
          showItem = this.data.cityAgent;
          console.log("市级代理")
          break;
        case 2:
          showItem = this.data.areaAgent;
          console.log("区及代理")
          break;    
      }
      console.log(showItem)
      that.setData({
        currentTab: e.target.dataset.current,
        showItem: showItem
      })
    }
  }
})  